(in-package :graph-model)

(defclass path ()
  ((arcs :initform nil
	 :initarg :arcs
	 :accessor path-arcs)))

(defmethod print-object ((path path) stream)
  (format stream "[")
  (display-sequence (path-arcs path) stream :sep ",")
  (format stream "]"))

(defun make-path (&optional arcs)
  (make-instance 'path :arcs arcs))

(defmethod path-cons ((arc arc) (path path))
  (let ((arcs (path-arcs path)))
    (when arcs
      (assert (eq (extremity arc) (origin (car arcs)))))
    (make-path
     (cons arc arcs))))

(defmethod path-origins ((path path))
  (mapcar #'origin (path-arcs path)))

(defmethod path-extremities ((path path))
  (mapcar #'extremity (path-arcs path)))

(defmethod get-nodes ((path path))
  (node-union
   (path-origins path)
   (path-extremities path)))
  
(defmethod weight ((path path))
  (weight (path-arcs path)))

(defmethod path-cycle-p ((path path))
  (let ((arcs (path-arcs path)))
    (and
     arcs
     (eq (origin (first arcs)) (extremity (car (last arcs)))))))
